﻿using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using ImageProcessing.Common;

namespace ImageProcessing.Storage
{
    public class OnlineImageArchiver : BaseImageArchiver
    {
        public OnlineImageArchiver()
        {
            string imagePath = HelperMethods.GetImagePath();

            if (!Directory.Exists(imagePath))
                Directory.CreateDirectory(imagePath);
        }

        protected override Stream OpenStorageFileStream(string fileName)
        {
            string combinedPathName = HelperMethods.GetImageFileNamePath(fileName);
            return File.Open(combinedPathName, FileMode.Open);
        }

        protected override Stream CreateStorageFileStream(string fileName)
        {
            string combinedPathName = HelperMethods.GetImageFileNamePath(fileName);
            return File.Create(combinedPathName);
        }

        protected override List<string> GetRawFilesListing()
        {
            DirectoryInfo directoryInfo = new DirectoryInfo(HelperMethods.GetImagePath());

            var fileInfo = directoryInfo.GetFiles("*" + HelperMethods.RawFileExtension);

            return fileInfo.Select(x => x.FullName).ToList();
        }
    }
}
